package cn.dida.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.dida.model.DeliveryInfo;
import cn.dida.model.HttpResponseBodyWrapper;
import cn.dida.model.UserSession;
import cn.dida.service.DeliverInfoService;
/**
 * 兑奖管理中    物流配送信息 
 * @author lisha
 * @date 2016-11-21 11:02
 * */
@Controller
public class DeliverInfoController extends BaseController {
	@Autowired
	private DeliverInfoService  infoService;
	
	
	/**
	 * 增加物流配送
	 * @param request
	 * @param info 物流配送实体类
	 * @return HttpResponseBodyWrapper 封装操作标记（ true新增成功，false新增失败）
	 * @throws Exception
	 */
	@ResponseBody
    @PostMapping("/deliverInfo")
    public HttpResponseBodyWrapper postBrand(HttpServletRequest request, @RequestBody DeliveryInfo info) throws Exception {
		UserSession userSession = getUserSession(request);
        info.setcAdmin(userSession.getAccount());
        
        Boolean result = infoService.insertDeliverInfo(info);
        return new HttpResponseBodyWrapper(result);
    }
	/**
	 * 修改物流配送
	 * @param request
	 * @param info 物流配送实体类
	 * @return HttpResponseBodyWrapper 封装操作标记（ true更新成功，false更新失败）
	 * @throws Exception
	 */
	@ResponseBody
    @PutMapping("/deliverInfo/{id}")
    public HttpResponseBodyWrapper putBrand(HttpServletRequest request, @RequestBody DeliveryInfo info) throws Exception {
        UserSession userSession = getUserSession(request);

        Boolean result = infoService.updateDeliverInfo(info);
        return new HttpResponseBodyWrapper(result);
    }
	
	/**
	 * 获取物流配送详情
	 * @param request
	 * @param id 物流配送id
	 * @return HttpResponseBodyWrapper 封装单个物流配送实体数据
	 * @throws Exception
	 */
	@ResponseBody
    @GetMapping("/deliverInfo/{id}")
    public HttpResponseBodyWrapper getBrand(HttpServletRequest request, @PathVariable Integer id) throws Exception {
		DeliveryInfo info = infoService.getDeliverInfoById(id);
        return new HttpResponseBodyWrapper(info);
    }
}
